package top.szhome.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.szhome.framework.core.tools.support.Resp;
import top.szhome.framework.core.tools.util.TreeUtil;
import top.szhome.framework.starter.db.support.SimpleController;
import top.szhome.system.convert.MenuConverter;
import top.szhome.system.dto.MenuDTO;
import top.szhome.system.entity.Menu;
import top.szhome.system.qry.MenuQry;
import top.szhome.system.service.MenuService;
import top.szhome.system.vo.MenuVO;

import java.util.List;

/**
 * 菜单 接口实现
 *
 * @author 唐加利
 * @date 2023/07/31
 **/
@AllArgsConstructor
@RestController
@RequestMapping("/system/menu")
@Tag(name = "菜单")
public class MenuController extends SimpleController<MenuService, MenuConverter, MenuQry, MenuDTO, Menu, MenuVO> {

    /**
     * 获取菜单树
     *
     * @param query
     * @return
     */
    @Operation(summary = "菜单树", description = "获取菜单树")
    @GetMapping("tree")
    public Resp<List<MenuVO>> tree(MenuQry query) {
        List<MenuVO> menus = this.getBaseService().list(query);
        return Resp.success(TreeUtil.tree(menus));
    }
    
    /**
     * 获取角色分配的菜单列表
     * @param roleId
     * @return
     */
    @Operation(summary = "角色分配的菜单集", description = "获取指定角色已分配的菜单集")
    @GetMapping("role-menu")
    public Resp<List<MenuVO>> getMenusOfRole(Long roleId, boolean tree){
        return Resp.success(getBaseService().getMenusOfRole(roleId, tree));
    }
}
